<?php

class NewsController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        $view = $this->view;
        
        $cateId = $this->_request->getParam('cateid', 1);
        $view->cateId = $cateId;
        
        //获取脚注信息
        $post = new Business_Post();
        $footInfo = $post->getByCateId(3);
        if (isset($footInfo[0]) && isset($footInfo[0]['content'])) {
        	$view->footInfo = $footInfo[0]['content'];
        } else {
        	$view->footInfo = '';
        }
        
        $news = new Business_News();
        //当前页码
        $view->page = $page = $this->_request->getParam('page', 1);
        //记录总数
        $amount = $news->getByCateIdAmount($cateId);
        $view->amount = $amount;
        //每页显示
        $rowCount = Zend_Registry::get('data')->news->numPerPage;
        $view->rowCount = $rowCount;
        //总页数
        $view->total = $total = ceil($amount / $rowCount);
        //页码超过范围处理
        if ($page < 1) {
        	$view->page = $page = 1;
        }
        if ($page > $total) {
        	$view->page = $page = $total;
        }
        
        
        $category = new Business_Category();
        $category->setType('news');
        $categories = $category->getAll();
        $view->categories = $categories;
        
        $newsList = $news->getByCateId($cateId, $page, $rowCount);
        $view->newsList = $newsList;
    }
    
    public function detailAction()
    {
        $view = $this->view;
        $newsId = $this->_request->getParam('newsid', 1);
        
        //获取脚注信息
        $post = new Business_Post();
        $footInfo = $post->getByCateId(3);
        if (isset($footInfo[0]) && isset($footInfo[0]['content'])) {
        	$view->footInfo = $footInfo[0]['content'];
        } else {
        	$view->footInfo = '';
        }
        
        $category = new Business_Category();
        $category->setType('news');
        $categories = $category->getAll();
        $view->categories = $categories;
        
        $news = new Business_News();
        $newsInfo = $news->getById($newsId);
        $view->newsInfo = $newsInfo;
        
    }
}